import { ref } from 'vue'
import { defineStore } from 'pinia'
import { constantRoute } from '@/router/routes.js'
import { resetRouter } from '@/router/index.js'

export const useMenuStore = defineStore('menu', () => {
  // 路由规则
  const menuList = ref([])
  //  是否添加路由了
  const isAddRoute = ref(false)

  // 修改路由规则
  const setMenuList = (asyncRoutes) => {
    menuList.value = [...constantRoute, ...asyncRoutes]
  }
  // 清空路由规则
  const clearMenuList = () => {
    menuList.value = []
    isAddRoute.value = false
    resetRouter()
  }
  // 修改isAddRoute
  const setIsAddRoute = (v) => {
    isAddRoute.value = v
  }

  return {
    menuList,
    isAddRoute,
    setMenuList,
    clearMenuList,
    setIsAddRoute
  }
})
